import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;

public class GraphicsHelper {
    // 显示PNG图片的方法
    public static void putimagePNG(int pictureX, int pictureY, BufferedImage picture, Graphics g) {
        if (g != null && picture != null) {
            g.drawImage(picture, pictureX, pictureY, null);
        }
    }
    
    // 获取延迟时间的方法
    public static int getDelay() {
        // 这里可以根据需求返回适当的延迟值
        return 16; // 默认返回约60FPS对应的延迟时间(1000ms/60 ≈ 16.67ms)
    }
    
    // 加载图片的辅助方法
    public static BufferedImage loadImage(String filePath) {
        try {
            return ImageIO.read(new File(filePath));
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    // 将图片中指定颜色变为透明
    public static BufferedImage makeColorTransparent(BufferedImage image, Color color) {
        BufferedImage dest = new BufferedImage(
                image.getWidth(), image.getHeight(),
                BufferedImage.TYPE_INT_ARGB);
        int targetRGB = color.getRGB() | 0xFF000000; // 确保alpha为255
        for (int y = 0; y < image.getHeight(); y++) {
            for (int x = 0; x < image.getWidth(); x++) {
                int pixel = image.getRGB(x, y);
                if ((pixel | 0xFF000000) == targetRGB) {
                    dest.setRGB(x, y, 0x00FFFFFF & pixel); // 透明
                } else {
                    dest.setRGB(x, y, pixel);
                }
            }
        }
        return dest;
    }
} 